﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Reflection;

namespace AMStudio.Common
{
    public static class RuntimeConfig
    {
        public static DataTable RTDBTags;
        public static DataTable PLCPorts;
        public static DataTable Conditions;
        public static DataTable Errors;

        public static void Init()
        {
            string modulePath = Path.GetDirectoryName(Assembly.GetCallingAssembly().GetModules()[0].FullyQualifiedName);
            string io_config_file = Path.Combine(modulePath, "cfg\\IO_Config.xls");
            RTDBTags = SimpleExcelReader.LoadDataFromExcel(io_config_file, "RTDB");
            PLCPorts = SimpleExcelReader.LoadDataFromExcel(io_config_file, "PLC_Ports");
            string condition_file = Path.Combine(modulePath, "cfg\\ConditionList_en-US.xls");
            string error_file = Path.Combine(modulePath, "cfg\\Error_en-US.xls");
            Conditions = SimpleExcelReader.LoadDataFromExcel(condition_file, "CONDITION_LIST");
            Errors = SimpleExcelReader.LoadDataFromExcel(error_file, "ERROR_LIST");
        }

        public static void SetLanguage(string culture)
        {
            string modulePath = Path.GetDirectoryName(Assembly.GetCallingAssembly().GetModules()[0].FullyQualifiedName);

            string cont_list_file = Path.Combine(modulePath, "cfg\\ConditionList_" + culture + ".xls");
            string err_list_file = Path.Combine(modulePath, "cfg\\Error_" + culture + ".xls");
            Conditions = SimpleExcelReader.LoadDataFromExcel(cont_list_file, "CONDITION_LIST");
            Errors = SimpleExcelReader.LoadDataFromExcel(err_list_file, "ERROR_LIST");
        }
    }
}
